# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=libspectre
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.9
pkgrel=1
arch=('any')
pkgdesc="libspectre is a small library for rendering PostScript documents. It provides a convenient easy to use API for handling and rendering PostScript documents (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-ghostscript"
         "${MINGW_PACKAGE_PREFIX}-cairo")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-libidn"
            "${MINGW_PACKAGE_PREFIX}-pkg-config"
            "libtool"
            "automake-wrapper"
            "autoconf"
            "make")
options=('strip' 'staticlibs')
license=("GPL 2")
url="https://www.freedesktop.org/wiki/Software/libspectre/"
source=(https://libspectre.freedesktop.org/releases/${_realname}-${pkgver}.tar.gz
        libspectre-0.2.9-mingw-fix-decoration.patch
        libspectre-0.2.9-fix-include-dirs.patch)
sha256sums=('49ae9c52b5af81b405455c19fe24089d701761da2c45d22164a99576ceedfbed'
            '88a3ed9d3175f88255fc91b0651eb61a75a1168f329be864b7c235b9d9834f0b'
            '2d1a01a512d66b2cd60b0505f9b80a036461a2f549d28a4de980b1b015d70dd5')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/libspectre-0.2.9-mingw-fix-decoration.patch
  patch -p1 -i ${srcdir}/libspectre-0.2.9-fix-include-dirs.patch
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR=${pkgdir} install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
